package com.zhiche.lisa.bms.controller.driver;

import com.zhiche.lisa.bms.service.driver.ICalcDriverCost;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * Created by zhaoguixin on 2018/9/11.
 */
@RestController
@RequestMapping("/inner/calcDriverCost")
@Slf4j
@Api(description = "燃油价格", tags = {"燃油价格"})
public class CalcDriverCostController {

    @Autowired
    private ICalcDriverCost calcDriverCost;

    @PostMapping(value = "/getWaybillCostByCalc")
    @ApiOperation(value = "计算人送运单价格", notes = "计算人送运单价格", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Integer.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Map<Integer, Object>> getWaybillCostByCalc(
            @ApiParam(name = "vehicleClassifyId", value = "标准车型编码", required = true) String vehicleClassifyId,
            @ApiParam(name = "oProvince", value = "起运省", required = true) String oProvince,
            @ApiParam(name = "oTag", value = "起运市", required = true) String oTag,
            @ApiParam(name = "dProvice", value = "目的市", required = true) String dProvice,
            @ApiParam(name = "dTag", value = "目的市", required = true) String dTag,
            @ApiParam(name = "extraCost", value = "附加费用") BigDecimal extraCost,
            @ApiParam(name = "effectDate", value = "有效时间") String effectDate) {
        log.info("CalcDriverCostController.getWaybillCostByCalc para vehicleClassifyId:{}, oProvince:{}, oTag:{}," +
                "dProvice:{}, dTag:{}, extraCost:{}, effectDate: {}", vehicleClassifyId, oProvince, oTag, dProvice, dTag, extraCost, effectDate);
        RestfulResponse<Map<Integer, Object>> response = new RestfulResponse<>(0, "success", null);
        try {
            Date effectDateNew = new Date();
            if (StringUtils.isNotBlank(effectDate)) {
                effectDateNew = new Date(Long.valueOf(effectDate));
            }
            Map<Integer, Object> cost = calcDriverCost.getWaybillCostByCalc(vehicleClassifyId, oProvince, oTag, dProvice,
                    dTag, extraCost, effectDateNew);
            response.setData(cost);
            return response;
        } catch (Exception e) {
            response.setCode(-1);
            response.setMessage(e.getMessage());
            return response;
        }
    }

    @PostMapping(value = "/getScMap")
    @ApiOperation(value = "获取费用基础数据", notes = "获取费用基础数据", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Integer.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Map<Integer, Object>> getScMap
            (@ApiParam(name = "vehicleClassifyId", value = "标准车型编码", required = true) String vehicleClassifyId) {
        log.info("CalcDriverCostController.getWaybillCostByCalc para vehicleClassifyId:{}}", vehicleClassifyId);
        RestfulResponse<Map<Integer, Object>> response = new RestfulResponse<>(0, "success", null);
        try {
            Map<Integer, Object> cost = calcDriverCost.getScMap(vehicleClassifyId);
            response.setData(cost);
            return response;
        } catch (Exception e) {
            response.setCode(-1);
            response.setMessage(e.getMessage());
            return response;
        }
    }

}
